<template>
  <div class="realtime-metrics">
    <div v-for="(metric, index) in metrics" :key="index" class="metric-item">
      <div class="metric-header">
        <span>{{ metric.name }}</span>
        <el-tag :type="getStatusType(metric)">{{ metric.value }}{{ metric.unit }}</el-tag>
      </div>
      <el-progress
          :percentage="(metric.value / metric.threshold) * 100"
          :status="getProgressStatus(metric)"
          :format="() => ''"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import type { PropType } from 'vue'
defineProps<{
  metrics: Array<{
    name: string
    value: number
    unit: string
    threshold: number
  }>
}>()

const getStatusType = (metric: any) => {
  return metric.value > metric.threshold ? 'danger' : 'success'
}

const getProgressStatus = (metric: any) => {
  return metric.value > metric.threshold ? 'exception' : 'success'
}
</script>

<style scoped>
.realtime-metrics {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.metric-item {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 8px;
}

.metric-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}
</style>